package com.example.android_day4;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RestaurantViewAdapter extends BaseAdapter {

	private Context mContext;
	private List<RestaurantXmlDataModel> mListArray;
	private LayoutInflater mInflater;

	public RestaurantViewAdapter(Context context,
			List<RestaurantXmlDataModel> objects) {
		this.mContext = context;
		this.mListArray = objects;
		this.mInflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return mListArray.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mListArray.get(arg0);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		RestaurantXmlDataModel model = mListArray.get(position);

		if (convertView == null) {
			convertView = mInflater.inflate(
					R.layout.activity_restaurant__view_listview_row, null);
		}

		if (model != null) {

			TextView foodname = (TextView) convertView
					.findViewById(R.id.listview_row_food_name);
			foodname.setText(model.getStrName());
			TextView kcal = (TextView) convertView
					.findViewById(R.id.listview_row_time);
			kcal.setText(model.getStrTime());
			TextView price = (TextView) convertView
					.findViewById(R.id.listview_row_price);
			price.setText(model.getStrPrice());
		}

		return convertView;

	}
}
